var param = {}, formId = 'queryForm', url = "https://chief.yifengx.com/log/log/BizLogService/listBizLog";

var detail = null ;
(function () {
    /**进行表格数据初始化*/
	$.openx.pageSize = 30;
    var data = $.openx.getJsonObj(formId);
    data.from = ($.openx.pageNumber-1) * $.openx.pageSize;
    data.size = $.openx.pageSize;
    initTable(url,data);
})();


function initTable(url,data){
	var tableData =null ;
	var param = $.toJSON(data);
	$.ajaxSettings.async = false;
    $.ajax({
    	type: 'POST',
		url:url,
		data:param,
		success:function(data){
			tableData = data;
		},
		contentType:'application/json'
		
	});
   console.log(tableData);
	$.ajaxSettings.async = true;
	$("#table").bootstrapTable("destroy");
	if(tableData && tableData.length>0){
		$(".nextPage").prop("disabled", false);
		$("#table").bootstrapTable({
			 data:tableData,
			 striped:true,
	         columns:[
	                {field: 'Number',title: '',width:'5px',formatter: function (value, row, index) {
	                        return index+1;
	                    }},
	                {field:'methodDesc',title:'操作名',align:'center',valign: 'middle'}, 
	                {field:'userCode',title:'用户编码',align:'center',valign: 'middle'}, 
	                {field:'queryString',title:'请求参数',align:'center',valign: 'middle',formatter:function(){
	                	return param;
	                }}, 
	                {field:'createTime',title:'操作时间',align:'center',valign: 'middle',formatter:function(value){
	                	return $.openx.formatDate(new Date(value));
	                }},
	                {title:'详情',align:'center',valign: 'middle',formatter:fomartRow}
	               
	                ]
		 });
	}else{
		$(".nextPage").prop("disabled", true);
//		$.openx.pageNumber = 1 ;
		layer.msg("没有找到匹配的记录!!!");
	}
	$("#pageNumber").html($.openx.pageNumber);
}
//查询按钮触发
$.openx.query = function () {
	var data = $.openx.getJsonObj(formId);
    data.from = ($.openx.pageNumber-1) * $.openx.pageSize;
    data.size = $.openx.pageSize;
    initTable(url,data);
}

function resetForm(){
	$.openx.pageNumber=1;
	$("#userCode").val("");
	$("#queryString").val("");
	var data = $.openx.getJsonObj(formId);
    data.from = ($.openx.pageNumber-1) * $.openx.pageSize;
    data.size = $.openx.pageSize;
    initTable(url,data);
}

function previPage(){
	if($.openx.pageNumber > 1){
		$.openx.pageNumber=$.openx.pageNumber-1;
		$.openx.query();
	}else{
		layer.msg("已是第一页");
	}
	
}

function nextPage(){
	$.openx.pageNumber=$.openx.pageNumber+1;
	$.openx.query();
}

function fomartRow(value, row, index){
//	detail= row;
//	row.header = JSON.stringify(row.header));
	try{
		row.header = JSON.parse(row.header);
		try{
			row.header.userInfo = JSON.parse(row.header.userInfo);
		}catch(msg){
    		row.header.userInfo = null;
    	}
	}catch(msg){
		row.header = null;
	}
//	try{
//		row.params = JSON.parse(row.params);
//	}catch(msg){
//		row.params = null;
//	}
	try{
		row.createTime = $.openx.formatDate(new Date(row.createTime));
	}catch(msg){
		row.params = null;
	}
	
	
	return '<a href=\'javascript:void(0)\' onclick=\'showDetail('+JSON.stringify(row)+')\'>查看详情</a>';
}

function showDetail(row){
	console.log(row);
	var html = $.openx.innerHtml('logDetailTpl')
	laytpl($.openx.innerHtml('logDetailTpl')).render(row, function (html) {
                $.openx.openLayer(null, '日志详情', html, true)
            });
//	
	
}